package code;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main_0409 {
    //双指针
    //回朔
    //剪枝
    //dfs
    private Character[] arr = new Character[]{'a', 'e', 'i', 'o', 'u'};
    private String word = "oaaaeeiioouo";

    public int longestBeautifulSubstring(String word) {
        int sum = 0;
        int left = word.indexOf('a');
        if (left == -1) {
            return 0;
        }
        int index = 0;
        for (int i = left; i < word.length(); i++) {
            if (arr[index] == word.charAt(i)) {
                continue;
            } else if ((index + 1) < arr.length && arr[index + 1] == word.charAt(i)) {
                index++;
            } else {
                if (arr[index] == 'u') {
                    sum = Math.max(sum, i - left);
                }
                while (i < word.length() && word.charAt(i) != 'a') {//
                    i++;
                }
                index = 0;
                left = i;
            }
        }
        if (arr[index] == 'u') {
            sum = Math.max(sum, word.length() - left);
        }
        return sum;
    }

    public static void main(String[] args) {
        String word = "aeiouopaeiouuuuuu";
        Main_0409 main_0409 = new Main_0409();
        int i = main_0409.longestBeautifulSubstring(word);
        System.out.println(i);

    }
}
